<template>
  <div class="loading-animation">
    <div class="spinner">
      <div class="ring"></div>
      <div class="ring"></div>
      <div class="ring"></div>
    </div>
    <p v-if="text" class="loading-text">{{ text }}</p>
  </div>
</template>

<script setup lang="ts">
withDefaults(defineProps<{
  text?: string
}>(), {
  text: '加载中...'
})
</script>

<style lang="scss" scoped>
.loading-animation {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.spinner {
  position: relative;
  width: 60px;
  height: 60px;
}

.ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border: 3px solid transparent;
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
  
  &:nth-child(1) {
    animation-delay: 0s;
    border-top-color: var(--color-primary);
  }
  
  &:nth-child(2) {
    animation-delay: 0.3s;
    border-top-color: var(--color-secondary);
    width: 80%;
    height: 80%;
    top: 10%;
    left: 10%;
  }
  
  &:nth-child(3) {
    animation-delay: 0.6s;
    border-top-color: var(--color-accent);
    width: 60%;
    height: 60%;
    top: 20%;
    left: 20%;
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading-text {
  margin-top: 1rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  animation: pulse 2s ease-in-out infinite;
}
</style>
